home *** CD-ROM | disk | FTP | other *** search
/ Megahits 5 / Megahits 5 (1994)(GTI - Rhein-Main-Soft)(DE)(Disc 2 of 2)[!].iso / archive / show / superview_lib6_3.lha / superview-lib / Programmers / Example_Tools / SimpleView / SimpleView.c < prev    next >
C/C++ Source or Header  |  1994-06-06  |  13KB  |  409 lines

  1. /* ======================================================================== */
  2. /* = Programmname    : SimpleView V6.1                      = */
  3. /* =                                      = */
  4. /* ======================================================================== */
  5. /* = Author/Copyright : (c) 1993-94 by Andreas Ralph Kleinert.            = */
  6. /* =               Freeware. All rights reserved.              = */
  7. /* =                                      = */
  8. /* =                   Use it as an example for programming               = */
  9. /* =                   superview.library !                                = */
  10. /* =                                      = */
  11. /* ======================================================================== */
  12. /* = Function          : SVObject operations :                             = */
  13. /* =                - Write WB-Screen content (IFF-ILBM/-ACBM)        = */
  14. /* =                - Show graphics         (all SVObjects)          = */
  15. /* =                - Convert graphics     (IFF-ILBM/-ACBM)         = */
  16. /* ======================================================================== */
  17. /* = Last Update      : 28.5.1994                      = */
  18. /* =                                      = */
  19. /* ======================================================================== */
  20. /* = Remarks          : Needs "asl.library" V37+                          = */
  21. /* =                and "superview.library" V2+.                      = */
  22. /* =                                      = */
  23. /* =            Based on KILBM V1.32.                             = */
  24. /* =                                      = */
  25. /* ======================================================================== */
  26. /* = Compiler          : SAS/C V6.51                        = */
  27. /* =                (smakefile)                                       = */
  28. /* ======================================================================== */
  29.  
  30. #include <intuition/intuitionbase.h>
  31.  
  32. #include <superview/superview.h>
  33.  
  34. #include <libraries/asl.h>
  35. #include <workbench/startup.h>
  36. #include <exec/interrupts.h>
  37.  
  38. #include <proto/exec.h>
  39. #include <proto/dos.h>
  40. #include <proto/intuition.h>
  41. #include <proto/graphics.h>
  42. #include <proto/asl.h>
  43. #include <proto/superview.h>
  44.  
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <string.h>
  48.  
  49.  
  50.    /* Help- and Info- Texts */
  51.  
  52. char entry1_text  [] = "\2331;32;40mSimpleView V6.1 \2330;32;40m\2333;32;40m(FREEWARE)\2330;32;40m\n(c) 1993-94 by Andreas Ralph Kleinert.\nAndreas R. Kleinert, Grube Hohe Grethe 23, D-57074 Siegen, Germany.\n";
  53. char entry2_text  [] = "Uses superview.library to write, show and convert IFF-ILBM/-ACBM.\n";
  54. char entry3_text  [] = "USAGE : \2330;33;40mSimpleView\2330;31;40m -[w | wp | wa | r | s | ci | cip | ca | ?] <PicFileName>\n";
  55. char entry4_text  [] = "   '-w'   -> Write current screen page to IFF-ILBM-file (unpacked).\n";
  56. char entry5_text  [] = "   '-wp'  -> Write current screen page to IFF-ILBM-file (packed).\n";
  57. char entry6_text  [] = "   '-wa'  -> Write current screen page to IFF-ACBM-file.\n";
  58. char entry7_text  [] = "   '-s'   -> Show an IFF-ILBM-/ACBM-file (optional).\n";
  59. char entry8_text  [] = "   '-ci'  -> Convert IFF-ACBM to IFF-ILBM (unpacked).\n";
  60. char entry9_text  [] = "   '-cip' -> Convert IFF-ACBM to IFF-ILBM (packed).\n";
  61. char entry10_text [] = "   '-ca'  -> Convert IFF-ILBM to IFF-ACBM.\n";
  62. char entry11_text [] = "   '?'    -> This text.\n";
  63.  
  64.  
  65. char ver_text [] = "\0$VER: SimpleView V6.1 (28.5.94)";
  66.  
  67.  
  68. /* *************************************************** */
  69. /* *                             * */
  70. /* * Error-Messages for Leave() and KF_Message()     * */
  71. /* *                             * */
  72. /* *************************************************** */
  73.  
  74. char intuitionlib_text    [] = "You need \42intuition.library\42 V33+ !";
  75. char graphicslib_text    [] = "You need \42graphics.library\42 V33+ !";
  76. char asllib_text     [] = "You need \42asl.library\42 V37+ !";
  77. char svlib_text     [] = "You need \42superview.library\42 V2+ !";
  78.  
  79.  
  80. /* *************************************************** */
  81. /* *                             * */
  82. /* * MACROs for Version-Tests                 * */
  83. /* *                             * */
  84. /* *************************************************** */
  85.  
  86. #define LibVer(x) ( ((struct Library *) x)->lib_Version )
  87. #define OS_VER      LibVer(SysBase)
  88.  
  89.  
  90. /* *************************************************** */
  91. /* *                             * */
  92. /* * Function Declarations                 * */
  93. /* *                             * */
  94. /* *************************************************** */
  95.  
  96. void __regargs SimpleView_Show(char *filename);
  97. void __regargs SimpleView_Write(char *filename, ULONG type);
  98. void __regargs SimpleView_Convert(char *filename, ULONG type);
  99.  
  100.  
  101. void __regargs Leave(char *endtext, long code);
  102.  
  103.  
  104.    /* Functions from module "SimpleView_Subs.o" : */
  105.  
  106. extern void __stdargs K_Printf(char *formatstring, ...);
  107.  
  108.  
  109. /* *************************************************** */
  110. /* *                             * */
  111. /* * Additional Base Declarations             * */
  112. /* *                             * */
  113. /* *************************************************** */
  114.  
  115. extern struct ExecBase *SysBase;
  116.  
  117. struct IntuitionBase *IntuitionBase = N;
  118. struct GfxBase       *GfxBase       = N;
  119. struct Library       *AslBase       = N;
  120. struct SuperViewBase *SuperViewBase = N;
  121.  
  122.  
  123. /* *************************************************** */
  124. /* *                             * */
  125. /* * <CTRL-C>-Handling                     * */
  126. /* *                             * */
  127. /* *************************************************** */
  128.  
  129. void CXBRK(void);
  130. void CXBRK(void)
  131. {
  132.  Leave("\n*** BREAK ***\n", 0);
  133. }
  134.  
  135. /* *************************************************** */
  136. /* *                             * */
  137. /* * MAIN                         * */
  138. /* *                             * */
  139. /* *************************************************** */
  140.  
  141. extern struct WBStartup *WBenchMsg;
  142. char                *wbloadname = N;
  143. long                     wb         = FALSE;
  144.  
  145. void main(long argc, char **argv)
  146. {
  147.  if(!argc)
  148.   {
  149.    wb = TRUE;
  150.  
  151.    if(WBenchMsg->sm_NumArgs>1) wbloadname = WBenchMsg->sm_ArgList[1].wa_Name;
  152.   }
  153.  
  154.  if( argc > 3 || (argv[1][0] =='?')||(argv[2][0] =='?'))
  155.   {
  156.    K_Printf("%s%s%s%s%s%s%s%s%s%s%s", entry1_text, entry2_text, entry3_text, entry4_text, entry5_text, entry6_text, entry7_text, entry8_text, entry9_text, entry10_text, entry11_text);
  157.  
  158.    Leave(N, 0);
  159.   }
  160.  
  161.  IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 33);
  162.  if(!IntuitionBase) Leave(intuitionlib_text, 100);
  163.  
  164.  GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 33);
  165.  if(!GfxBase) Leave(graphicslib_text, 101);
  166.  
  167.  AslBase = (struct Library *) OpenLibrary("asl.library", 37);
  168.  if(!AslBase) Leave(asllib_text, 102);
  169.  
  170.  SuperViewBase = (struct SuperViewBase *) OpenLibrary("superview.library", 2);
  171.  if(!SuperViewBase) Leave(svlib_text, 103);
  172.  
  173.  
  174.  /* Show */
  175.  
  176.  if(argc < 2 && !wbloadname)
  177.   {
  178.    struct FileRequester     *request;
  179.    struct TagItem __aligned  tags[4];
  180.    char                      namebuffer [256];
  181.  
  182.    namebuffer[0] = (char) 0;
  183.  
  184.    tags[0].ti_Tag  = (Tag)   ASL_Hail;
  185.    tags[0].ti_Data = (ULONG) "Select Picture to Display :";
  186.  
  187.    tags[1].ti_Tag  = (Tag)   ASL_OKText;
  188.    tags[1].ti_Data = (ULONG) " Display ";
  189.  
  190.    tags[2].ti_Tag  = (Tag)   ASL_CancelText;
  191.    tags[2].ti_Data = (ULONG) " Quit ";
  192.  
  193.    tags[3].ti_Tag  = (Tag)   TAG_DONE;
  194.    tags[3].ti_Data = (ULONG) N;
  195.  
  196.    request = AllocAslRequest(ASL_FileRequest, N);
  197.    if(request)
  198.     {
  199.      if(AslRequest(request, &tags[0]))
  200.       {
  201.        strcpy(namebuffer, request->rf_Dir);
  202.        if(    (namebuffer[strlen(namebuffer)-1] !=      ':')
  203.            && (namebuffer[strlen(namebuffer)-1] !=      '/')
  204.            && (namebuffer[0]                    != (char) 0) ) strcat(namebuffer, "/");
  205.  
  206.        strcat(namebuffer, request->rf_File);
  207.  
  208.        if(namebuffer[0] != (char) 0) SimpleView_Show(namebuffer);
  209.       }
  210.  
  211.      FreeAslRequest(request);
  212.     }
  213.   }else
  214.   {
  215.    if(wbloadname) SimpleView_Show(wbloadname);
  216.     else
  217.      {
  218.       /* Show */
  219.  
  220.       if(argv[1][0]!=(char) '-') SimpleView_Show(argv[1]); /* no option given,  */
  221.                                                            /* but PicFileName ! */
  222.  
  223.       if(!stricmp(argv [1],"-s"))  SimpleView_Show(argv[2]);
  224.  
  225.       /* Write */
  226.  
  227.       if(!stricmp(argv [1],"-w"))  SimpleView_Write(argv[2], SV_SUBTYPE_ILBM);
  228.       if(!stricmp(argv [1],"-wp")) SimpleView_Write(argv[2], SV_SUBTYPE_ILBM_01);
  229.       if(!stricmp(argv [1],"-wa")) SimpleView_Write(argv[2], SV_SUBTYPE_ACBM);
  230.  
  231.       /* Convert (Show & Write) */
  232.  
  233.       if(!stricmp(argv [1],"-ci"))  SimpleView_Convert(argv[2], SV_SUBTYPE_ILBM);
  234.       if(!stricmp(argv [1],"-cip")) SimpleView_Convert(argv[2], SV_SUBTYPE_ILBM_01);
  235.       if(!stricmp(argv [1],"-ca"))  SimpleView_Convert(argv[2], SV_SUBTYPE_ACBM);
  236.      }
  237.   }
  238.  
  239.  Leave(N, 0);
  240. }
  241.  
  242. /* *************************************************** */
  243. /* *                             * */
  244. /* * Show-Function                     * */
  245. /* *                             * */
  246. /* *************************************************** */
  247.  
  248. void __regargs SimpleView_Show(char *filename)
  249. {
  250.  APTR handle;
  251.  struct Window *win;
  252.  ULONG retval = SVERR_NO_ERROR;
  253.  
  254.  handle = SVL_AllocHandle(N);
  255.  if(handle)
  256.   {
  257.    if(!(retval = SVL_InitHandleAsDOS(handle, N)))
  258.     {
  259.      if(!(retval = SVL_SetWindowIDCMP(handle, IDCMP_MOUSEBUTTONS, N)))
  260.       {
  261.        if(!(retval = SVL_SetScreenType(handle, CUSTOMSCREEN, N)))
  262.         {
  263.          if(!(retval = SVL_SuperView(handle, filename)))
  264.           {
  265.            if(!(retval = SVL_GetWindowAddress(handle, &win, N)))
  266.             {
  267.              if(win)
  268.               {
  269.                WaitPort(win->UserPort);
  270.               }
  271.             }
  272.           }
  273.         }
  274.       }
  275.     }
  276.    
  277.    SVL_FreeHandle(handle);
  278.  
  279.   }else retval = SVERR_NO_HANDLE;
  280.  
  281.  if(retval) Leave(SVL_GetErrorString(retval), 0);
  282. }
  283.  
  284. /* *************************************************** */
  285. /* *                             * */
  286. /* * Write-Function                     * */
  287. /* *                             * */
  288. /* *************************************************** */
  289.  
  290. void __regargs SimpleView_Write(char *filename, ULONG type)
  291. {
  292.  APTR handle;
  293.  ULONG retval = SVERR_NO_ERROR;
  294.  
  295.  handle = SVL_AllocHandle(N);
  296.  if(handle)
  297.   {
  298.    if(!(retval = SVL_InitHandleAsDOS(handle, N)))
  299.     {
  300.      if(!(retval = SVL_SetWriteType(handle, type, N)))
  301.       {
  302.        if(!(retval = SVL_SetWriteName(handle, filename, N)))
  303.         {
  304.          if(!(retval = SVL_SetWriteScreen(handle, IntuitionBase->FirstScreen, N)))
  305.           {
  306.            retval = SVL_SuperWrite(handle);
  307.           }
  308.         }
  309.       }
  310.     }
  311.    
  312.    SVL_FreeHandle(handle);
  313.  
  314.   }else retval = SVERR_NO_HANDLE;
  315.  
  316.  if(retval) Leave(SVL_GetErrorString(retval), 0);
  317. }
  318.  
  319. /* *************************************************** */
  320. /* *                             * */
  321. /* * Convert-Function                     * */
  322. /* *                             * */
  323. /* *************************************************** */
  324.  
  325. void __regargs SimpleView_Convert(char *filename, ULONG type)
  326. {
  327.  APTR handleS, handleD;
  328.  
  329.  struct Screen       *sc        = N;
  330.  struct SV_GfxBuffer *gfxbuffer = N;
  331.  
  332.  ULONG retval = SVERR_NO_ERROR;
  333.  char newfilename [256];
  334.  
  335.  
  336.  handleS = SVL_AllocHandle(N);
  337.  if(handleS)
  338.   {
  339.    if(!(retval = SVL_InitHandleAsDOS(handleS, N)))
  340.     {
  341.      if(LibVer(SuperViewBase) > 5)
  342.       {
  343.        if(!(retval = SVL_ReadToGfxBuffer(handleS, filename))) retval = SVL_GetGfxBuffer(handleS, &gfxbuffer, N);
  344.       }
  345.  
  346.      if( (LibVer(SuperViewBase) < 6) || !gfxbuffer)
  347.       {
  348.        if(!(retval = SVL_SetWindowIDCMP(handleS, IDCMP_MOUSEBUTTONS, N)))
  349.         {
  350.          if(!(retval = SVL_SetScreenType(handleS, CUSTOMSCREEN, N)))
  351.           {
  352.            if(!(retval = SVL_SuperView(handleS, filename))) retval = SVL_GetScreenAddress(handleS, &sc, N);
  353.           }
  354.         }
  355.       }
  356.  
  357.      if(!retval)
  358.       {
  359.        handleD = SVL_AllocHandle(N);
  360.        if(handleD)
  361.         {
  362.          if(!(retval = SVL_InitHandleAsDOS(handleD, N)))
  363.           {
  364.            strcpy(newfilename, filename);
  365.            strcat(newfilename, ".conv");
  366.  
  367.            if(!(retval = SVL_SetWriteName(handleD, newfilename, N)))
  368.             {
  369.              if(!(retval = SVL_SetWriteType(handleD, type, N)))
  370.               {
  371.                if(sc)        retval = SVL_SetWriteScreen(handleD, sc,        N);
  372.                if(gfxbuffer) retval = SVL_SetGfxBuffer(  handleD, gfxbuffer, N);
  373.  
  374.                if(!retval) retval = SVL_SuperWrite(handleD);
  375.               }
  376.             }
  377.           }
  378.  
  379.          SVL_FreeHandle(handleD);
  380.         }
  381.       }
  382.     }
  383.    
  384.    SVL_FreeHandle(handleS);
  385.  
  386.   }else retval = SVERR_NO_HANDLE;
  387.  
  388.  if(retval) Leave(SVL_GetErrorString(retval), 0);
  389. }
  390.  
  391.  
  392. /* *************************************************** */
  393. /* *                             * */
  394. /* * LEAVE : Global Exit Function Replacement         * */
  395. /* *                             * */
  396. /* *************************************************** */
  397.  
  398. void __regargs Leave(char *endtext, long code)
  399. {
  400.  if(SuperViewBase) CloseLibrary((APTR) SuperViewBase);
  401.  if(AslBase)       CloseLibrary((APTR) AslBase);
  402.  if(GfxBase)       CloseLibrary((APTR) GfxBase);
  403.  if(IntuitionBase) CloseLibrary((APTR) IntuitionBase);
  404.  
  405.  if(endtext)       if(!wb) K_Printf("%s\n", endtext);
  406.  
  407.  exit(code);
  408. }
  409.